package com.ruoyi.web.controller.order;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.order.domain.SyProductReturn;
import com.ruoyi.order.service.ISyProductReturnService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品退货及退款Controller
 * 
 * @author ruoyi
 * @date 2024-12-19
 */
@RestController
@RequestMapping("/order/return")
public class SyProductReturnController extends BaseController
{
    @Autowired
    private ISyProductReturnService syProductReturnService;

    /**
     * 查询商品退货及退款列表
     */
    @PreAuthorize("@ss.hasPermi('order:return:list')")
    @GetMapping("/list")
    public TableDataInfo list(SyProductReturn syProductReturn)
    {
        startPage();
        List<SyProductReturn> list = syProductReturnService.selectSyProductReturnList(syProductReturn);
        return getDataTable(list);
    }

    /**
     * 导出商品退货及退款列表
     */
    @PreAuthorize("@ss.hasPermi('order:return:export')")
    @Log(title = "商品退货及退款", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SyProductReturn syProductReturn)
    {
        List<SyProductReturn> list = syProductReturnService.selectSyProductReturnList(syProductReturn);
        ExcelUtil<SyProductReturn> util = new ExcelUtil<SyProductReturn>(SyProductReturn.class);
        util.exportExcel(response, list, "商品退货及退款数据");
    }

    /**
     * 获取商品退货及退款详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:return:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") String orderId)
    {
        return success(syProductReturnService.selectSyProductReturnByOrderId(orderId));
    }

    /**
     * 新增商品退货及退款
     */
    @PreAuthorize("@ss.hasPermi('order:return:add')")
    @Log(title = "商品退货及退款", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SyProductReturn syProductReturn)
    {
        return toAjax(syProductReturnService.insertSyProductReturn(syProductReturn));
    }

    /**
     * 修改商品退货及退款
     */
    @PreAuthorize("@ss.hasPermi('order:return:edit')")
    @Log(title = "商品退货及退款", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SyProductReturn syProductReturn)
    {
        return toAjax(syProductReturnService.updateSyProductReturn(syProductReturn));
    }

    /**
     * 删除商品退货及退款
     */
    @PreAuthorize("@ss.hasPermi('order:return:remove')")
    @Log(title = "商品退货及退款", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable String[] orderIds)
    {
        return toAjax(syProductReturnService.deleteSyProductReturnByOrderIds(orderIds));
    }

    //courseOrderALL 查询所有课程订单数量
    @PreAuthorize("@ss.hasPermi('order:return:query')")
    @GetMapping(value = "/productReturnAll")
    public AjaxResult productReturnAll()
    {
        return success(syProductReturnService.productReturnAll());
    }
}
